<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrderCommissionTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('order_commission', function (Blueprint $table) {
            $table->id();
            $table->tinyInteger('type')->default(0)->comment('0=洗车订单,1=商城订单');
            $table->integer('user_id')->default(0)->comment('用户ID');
            $table->string('order_id')->nullable()->comment('订单编号');
            $table->integer('service_id')->default(0)->comment('服务ID');
            $table->string('service_name')->nullable()->comment('服务名称');
            $table->string('card_title')->nullable()->comment('洗车卡标题');
            $table->decimal('amount')->default(0.00)->comment('订单金额');

            $table->float('platform_rate')->default(0.00)->comment('平台分成比例');
            $table->decimal('platform_money')->default(0.00)->comment('平台分成金额');

            $table->integer('shop_id')->default(0)->comment('门店ID');
            $table->float('shop_rate')->default(0.00)->comment('门店分成比例');
            $table->decimal('shop_money')->default(0.00)->comment('门店分成');

            $table->integer('worker_id')->default(0)->comment('师傅ID');
            $table->float('worker_rate')->default(0.00)->comment('洗车小哥分成比例');
            $table->decimal('worker_money')->default(0.00)->comment('洗车小哥分成');

            $table->integer('agent_id')->default(0)->comment('代理商ID');
            $table->float('agent_rate')->default(0)->comment('代理商分成比例');
            $table->decimal('agent_money')->default(0.00)->comment('代理商分成');

            $table->integer('top_id')->default(0)->comment('上级用户ID');
            $table->float('top_rate')->default(0)->comment('上级用户分成比例');
            $table->decimal('top_money')->default(0.00)->comment('上级用户分成');

            $table->integer('top_top_id')->default(0)->comment('上级用户ID');
            $table->float('top_top_rate')->default(0)->comment('上级用户分成比例');
            $table->decimal('top_top_money')->default(0.00)->comment('上级用户分成');


            $table->dateTime('settle_time')->nullable()->comment('结算时间');
            $table->boolean('is_settle')->default(0)->comment('是否已结算:0=未结算,1=已结算,2=已取消');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order_commission');
    }
}
